package com.jeegit.ecms.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jeegit.common.annotation.Log;
import com.jeegit.common.enums.BusinessType;
import com.jeegit.ecms.domain.CmsVideoChapter;
import com.jeegit.ecms.service.ICmsVideoChapterService;
import com.jeegit.common.core.controller.BaseController;
import com.jeegit.common.core.domain.AjaxResult;
import com.jeegit.common.utils.poi.ExcelUtil;
import com.jeegit.common.core.page.TableDataInfo;

/**
 * 视频章节Controller
 * 
 * @author jeegit
 * @date 2022-06-27
 */
@Controller
@RequestMapping("/ecms/chapter")
public class CmsVideoChapterController extends BaseController
{
    private String prefix = "ecms/chapter";

    @Autowired
    private ICmsVideoChapterService cmsVideoChapterService;

    @RequiresPermissions("ecms:chapter:view")
    @GetMapping()
    public String chapter(CmsVideoChapter cmsVideoChapter, ModelMap mmap)
    {
    	mmap.put("cmsVideoChapter", cmsVideoChapter);
        return prefix + "/chapter";
    }

    /**
     * 查询视频章节列表
     */
    @RequiresPermissions("ecms:chapter:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsVideoChapter cmsVideoChapter)
    {
        startPage();
        List<CmsVideoChapter> list = cmsVideoChapterService.selectCmsVideoChapterList(cmsVideoChapter);
        return getDataTable(list);
    }

    /**
     * 导出视频章节列表
     */
    @RequiresPermissions("ecms:chapter:export")
    @Log(title = "视频章节", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsVideoChapter cmsVideoChapter)
    {
        List<CmsVideoChapter> list = cmsVideoChapterService.selectCmsVideoChapterList(cmsVideoChapter);
        ExcelUtil<CmsVideoChapter> util = new ExcelUtil<CmsVideoChapter>(CmsVideoChapter.class);
        return util.exportExcel(list, "视频章节数据");
    }

    /**
     * 新增视频章节
     */
    @GetMapping("/add")
    public String add(CmsVideoChapter cmsVideoChapter, ModelMap mmap)
    {
    	mmap.put("cmsVideoChapter", cmsVideoChapter);
        return prefix + "/add";
    }

    /**
     * 新增保存视频章节
     */
    @RequiresPermissions("ecms:chapter:add")
    @Log(title = "视频章节", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsVideoChapter cmsVideoChapter)
    {
        return toAjax(cmsVideoChapterService.insertCmsVideoChapter(cmsVideoChapter));
    }

    /**
     * 修改视频章节
     */
    @RequiresPermissions("ecms:chapter:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CmsVideoChapter cmsVideoChapter = cmsVideoChapterService.selectCmsVideoChapterById(id);
        mmap.put("cmsVideoChapter", cmsVideoChapter);
        return prefix + "/edit";
    }

    /**
     * 修改保存视频章节
     */
    @RequiresPermissions("ecms:chapter:edit")
    @Log(title = "视频章节", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsVideoChapter cmsVideoChapter)
    {
        return toAjax(cmsVideoChapterService.updateCmsVideoChapter(cmsVideoChapter));
    }

    /**
     * 删除视频章节
     */
    @RequiresPermissions("ecms:chapter:remove")
    @Log(title = "视频章节", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsVideoChapterService.deleteCmsVideoChapterByIds(ids));
    }
}
